package com.kly.order.db.dao.impl;
import com.fqgj.common.base.AbstractBaseMapper;
import com.kly.order.db.dao.MemberBenefitsDao;
import com.kly.order.db.entity.MemberBenefitsEntity;
import com.kly.order.db.entity.MemberEntity;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* User: 11437
* Date: 2023-06-01
* Time: 15:07:05.527
*/

@Repository
public class MemberBenefitsDaoImpl extends AbstractBaseMapper<MemberBenefitsEntity> implements MemberBenefitsDao {
    public List<MemberBenefitsEntity> selectByMemberCode(Map<String, Object> params) {
        return this.getSqlSession().selectList(this.getStatement("selectByMemberCode"), params);
    }

    public List<MemberBenefitsEntity> selectByMemberCodeAndTimesUsed(Map<String, Object> params) {
        return this.getSqlSession().selectList(this.getStatement("selectByMemberCodeAndTimesUsed"), params);
    }

    @Override
    public List<MemberBenefitsEntity> findLatestExpiryDatesByMemberCode(Map<String, Object> params) {
        return this.getSqlSession().selectList(this.getStatement("findLatestExpiryDatesByMemberCode"), params);
    }

    @Override
    public int batchInsert(List<MemberBenefitsEntity> list) {
        return this.getSqlSession().insert(this.getStatement("batchInsert"), list);
    }

    @Override
    public List<MemberBenefitsEntity> findAvailableServices(Map<String, Object> params) {
        return this.getSqlSession().selectList(this.getStatement("findAvailableServices"), params);
    }

    @Override
    public Integer selectFlashChatNum(String userCode, Integer benefitCode) {
        Map<String, Object> params = new HashMap<>();
        params.put("userCode", userCode);
        params.put("benefitCode", benefitCode);
        params.put("date", new Date());
        return this.getSqlSession().selectOne(this.getStatement("selectFlashChatNum"), params);
    }


    @Override
    public List<MemberBenefitsEntity> findAllBenefit(String userCode) {
        return this.getSqlSession().selectList(this.getStatement("findAllBenefit"), userCode);
    }

}